package com.sinodata.atmp.components
{
    import mx.validators.Validator;
    import mx.validators.StringValidator;
    import mx.core.UITextField;
    import mx.controls.TextInput;
    import mx.controls.DateField;

    public class DateCompareValidator extends StringValidator {
        import mx.validators.Validator;
        import mx.validators.ValidationResult;
    
        private var results:Array;        
        public function DateCompareValidator(){
            super();
        }
        
        public var beginDateSource:DateField;
        public var compareError:String = "开始时间必须小于结束时间";
        public var noBeginDateSourceError:String = "未指定开始时间";
                
        override protected function doValidation(value:Object):Array{
            results = [];       
            results = super.doValidation(value);
            if (results.length > 0)
            return results;
            
            if(beginDateSource != null){
                var beginDate:Date = beginDateSource.selectedDate;
                    if(beginDate >= value){
                        results.push(new ValidationResult(true, null, "Diff",compareError));
                        return results;
                    }
            }else{
                results.push(new ValidationResult(true, null, "NaN",noBeginDateSourceError));
                return results;
            }
            return results;
        }
    }
}